package com.wicketFlowTester;

import java.util.List;

public abstract class SelectiveIterator<T> {
    private int index;
    private final List<T> list;
    private final int[] indexes;
    private int indexCtr = 0;

    public SelectiveIterator(final List<T> list, final int... indexes) {
        this.index = indexes.length == 0 ? 0 : indexes[0];
        this.indexes = indexes;
        this.list = list;
        iterate();
    }

    private void iterate() {
        while (indexes.length == 0 ? index < list.size() : indexCtr < indexes.length) {
            final T obj = list.get(index);
            process(obj);
            if (indexes.length == 0) {
                index++;
            } else {
                indexCtr++;
                if (indexCtr < indexes.length) {
                    index = indexes[indexCtr];
                }
            }
        }
    }

    public abstract void process(T obj);
}
